package com.woniu.goods.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.woniu.goods.domain.GoodsType;
import com.woniu.goods.service.GoodsServiceImpl;
import com.woniu.goods.service.IGoodsService;
import com.woniu.goods.util.PageUtil;

@WebServlet("/per/list")
public class GoodsAction extends HttpServlet {
	IGoodsService gs = new GoodsServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//接收搜索条件  商品名称（模糊）   商品类型（精确）
		String gname = req.getParameter("gname");
		String tid = req.getParameter("tid");
		//接收当前页
		String pageNow = req.getParameter("pageNow");
		//查询的数据对象  PageUtil对象
		PageUtil pu = gs.findPageUtil(pageNow, gname, tid);
		//查询上类型集合
		List<GoodsType> types = gs.findAllType();
		
		//转发到列表的jsp页面
		req.setAttribute("pu", pu);
		req.setAttribute("types", types);
		
		//回显查询条件
		req.setAttribute("tid", tid);
		req.setAttribute("gname", gname);
		req.getRequestDispatcher("/jsp/list.jsp").forward(req, resp);
	}
	
}
